package cn.ctwing.ws.client.impl;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import cn.ctwing.ws.client.api.IWorker;
/**
 * 
 * @author eric
 *
 */
public class WSBlockingQueueWorker implements IWorker {
	
	/**
	 * 创建固定线程数的线程池
	 * @param nThreads 执行任务的线程数
	 * @param name 线程池名称，名称一定要与处理的业务相关，在调优时和查问题时很重要
	 * @return 线程池
	 */
	public static ExecutorService newFixedThreadPool(int nThreads,String name) {
		ThreadFactory tf = new ThreadFactory() {
			@Override
			public Thread newThread(Runnable r) {
				Thread t = new Thread(r);
				t.setName(name+"_"+t.getId());
				return t;
			}
			
		};
		ThreadPoolExecutor executor = new ThreadPoolExecutor(nThreads, nThreads,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(),
                tf
                );
        return executor;
    }

	
	

	@Override
	public void message(String channelId, String msg) {

	}

	@Override
	public void open(String channelId) {

	}

	public static void main(String[] args) {
	
	}
	
	

}
